//
//  SISSHouseAveragePriceCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2019/8/21.
//  Copyright © 2019 优房网. All rights reserved.
//

#import "SISSHouseAveragePriceCell.h"

@interface SISSHouseAveragePriceCell ()

/// leftLabel
@property (weak, nonatomic) UILabel *leftLabel;
/// priceLabel
@property (weak, nonatomic) UILabel *priceLabel;
/// Label
@property (weak, nonatomic) UILabel *unitLabel;
/// recommendPriceButton
@property (weak, nonatomic) UIButton *recommendPriceButton;

/// bottomLine
@property (weak, nonatomic) UIView *bottomLine;

@end
@implementation SISSHouseAveragePriceCell

- (void)setModel:(SISSHouseAveragePriceModel *)model {
    _model = model;
    self.leftLabel.text = model.leftTitle;
    self.priceLabel.text = model.middlePrice;
    [self.recommendPriceButton setTitle:model.rightButtonStr forState:UIControlStateNormal];
}

#pragma mark - 点击事件
- (void)recommendPriceButtonClickAction:(UIButton *)button {
    if ([self.delegate respondsToSelector:@selector(clickRecommendPriceButtonWithCell:)]) {
        [self.delegate clickRecommendPriceButtonWithCell:self];
    }
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *leftLabel = [[UILabel alloc] init];
    leftLabel.textColor = MAIN_TEXT_COLOR;
    leftLabel.font = [UIFont systemFontOfSize:16];
    leftLabel.text = @"政府评估";
    [self.contentView addSubview:leftLabel];
    self.leftLabel = leftLabel;
    
    UILabel *priceLabel = [[UILabel alloc] init];
    priceLabel.textColor = COLOR(0xFF6602);
    priceLabel.font = [UIFont boldSystemFontOfSize:21];
    priceLabel.text = @"{N}";
    [self.contentView addSubview:priceLabel];
    self.priceLabel = priceLabel;
    
    UILabel *unitLabel = [[UILabel alloc] init];
    unitLabel.numberOfLines = 0;
    unitLabel.textColor = MAIN_TEXT_COLOR;
    unitLabel.font = [UIFont boldSystemFontOfSize:21];
    unitLabel.text = @"元/平米";
    [self.contentView addSubview:unitLabel];
    self.unitLabel = unitLabel;
    
    UIButton *recommendPriceButton = [UIButton buttonWithType:UIButtonTypeCustom];
    recommendPriceButton.layer.cornerRadius = 4;
    recommendPriceButton.layer.masksToBounds = YES;
    [recommendPriceButton setTitle:@"使用均价" forState:UIControlStateNormal];
    recommendPriceButton.titleLabel.font = [UIFont systemFontOfSize:12];
    [recommendPriceButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [recommendPriceButton setBackgroundColor:COLOR(0x54B095)];
    [recommendPriceButton addTarget:self action:@selector(recommendPriceButtonClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:recommendPriceButton];
    self.recommendPriceButton = recommendPriceButton;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:bottomLine];
    self.bottomLine = bottomLine;
    
}

#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf
    CGFloat margin = 8.0;
    CGSize buttonSize = CGSizeMake(58, 32);
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView).offset(3 * margin);
        make.left.equalTo(weakSelf.contentView).offset(3 * margin);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(weakSelf.contentView).offset(-2 * margin);
        make.centerY.equalTo(weakSelf.contentView);
    }];
    
    [self.unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.priceLabel);
        make.left.equalTo(weakSelf.priceLabel.mas_right);
    }];
    
    [self.recommendPriceButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView).offset(-0.75 * margin);
        make.centerY.equalTo(weakSelf.contentView);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.leftLabel.mas_bottom).offset(3 * margin);
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}

@end
